package com.lanchewuyou.user.driver.yancheui;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.Toast;

import com.lanchewuyou.user.driver.R;
import com.lanchewuyou.user.driver.adapter.YancheFixAdapter;
import com.lanchewuyou.user.driver.bean.YancheFixItem;
import com.lanchewuyou.user.driver.modul.Config;

import java.util.ArrayList;
import java.util.List;

/**
 * 上传车辆维修信息
 */
public class YancheFixActivity extends AppCompatActivity {
    private ImageButton yancheFixBack;
    private GridView yancheFixGrid;
    private Button yancheFixNext;
    private List<YancheFixItem> yancheFixItemList = new ArrayList<>();
    private YancheFixAdapter yancheFixAdapter;
    private String[] itemLists;
    private static String DRIVERID;
    private Toast toast;

    private void showTextToast(String msg) {
        if (toast == null) {
            toast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
        } else {
            toast.setText(msg);
        }
        toast.show();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yanche_fix);
        initDatas();
        initViews();
    }

    private void initViews() {
        yancheFixNext = (Button) findViewById(R.id.yanche_fix_next_btn);
        yancheFixNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        yancheFixBack = (ImageButton) findViewById(R.id.yanche_fix_back);
        yancheFixBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        yancheFixGrid = (GridView) findViewById(R.id.yanche_fix_grid);
        yancheFixAdapter = new YancheFixAdapter(yancheFixItemList, YancheFixActivity.this);
        yancheFixGrid.setAdapter(yancheFixAdapter);
        yancheFixGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (yancheFixItemList.get(position).getPressType() == 0) {
                    yancheFixItemList.get(position).setPressType(1);
                } else {
                    yancheFixItemList.get(position).setPressType(0);
                }
                yancheFixAdapter.notifyDataSetChanged();
            }
        });
    }

    private void initDatas() {
        SharedPreferences sharedPreferences = getSharedPreferences(Config.PASSWORD_PATH, Activity.MODE_PRIVATE);
        DRIVERID = sharedPreferences.getString("driverid", "");
        itemLists = new String[]{"前杠", "左前叶子板", "左前门", "左后门", "左后叶子板", "机盖", "左反光镜", "右后门",
                "右前门", "右前叶子板", "后盖", "左大边", "右大边", "右反光镜", "左前轮毂", "左后轮毂", "右前轮毂", "右后轮毂", "后杠", "右后叶子板"};
        for (int i = 0; i < 20; i++) {
            YancheFixItem item = new YancheFixItem(0, itemLists[i], i);
            yancheFixItemList.add(item);
        }
    }

}
